package com.fanhang.samples.spring.security.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import com.fanhang.samples.spring.security.common.SampleUserDetails;
import com.fanhang.samples.spring.security.dao.UserDao;
import com.fanhang.samples.spring.security.po.User;
import com.fanhang.samples.spring.security.service.UserService;

/**
 * 用户
 */
public class UserServiceImpl implements UserService, UserDetailsService {

	@Autowired
	private UserDao userDao;

	@Override
	public User getByName(String name) {
		return userDao.get(name);
	}
	
	
	
	
	
	@Override
	public SampleUserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		User user = this.getByName(username);
		if (user == null) {
			throw new UsernameNotFoundException("用户名不存在");
		}
		return new SampleUserDetails(user);
	}
}
